Next | Prev | Up | Top | Contents | Index

Using Texture Objects

To create a texture object, bind an unused name to a texture target. The name is considered to be in use until you delete the texture. The following code fragment creates, defines, and binds texture objects with the names 1 and 2:

/* the first bind of 1 will create the texture object */
glBindTextureEXT( GL_TEXTURE_2D, 1 );
/* define the texture image and parameterss */
glTexImage2D( GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_BYTE, img1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );

/* the first bind of 2 will create the texture object */
glBindTextureEXT( GL_TEXTURE_2D, 2 );
/* define the texture image and parameters */
glTexImage2D( GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_BYTE, img2 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );

/* bind each texture object as scene is rendered */
glBindTextureEXT( GL_TEXTURE_2D, 1 );
<draw some primitive>
glBindTextureEXT( GL_TEXTURE_2D, 2 );
<draw some primitive>
There is also an example program in the source tree that demonstrates how to use texture objects.


Next | Prev | Up | Top | Contents | Index